using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CYZHAPI.Common.tools
{
    public class MyBase64
    {//MyBase64.DecodeBase64("UTF-8", requestInfo.Body);解密
       //编码
        public static string EncodeBase64(string code_type, string code)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            string encode = "";
            byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);//ASCII,UTF8
            try
            {
                encode = Convert.ToBase64String(bytes);
            }
            catch
            {
                encode = code;
            }
            return encode;
        }
        //解码
        public static string DecodeBase64(string code_type, string code)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            string decode = "";
            byte[] bytes = Convert.FromBase64String(code);
            try
            {
                decode = Encoding.GetEncoding(code_type).GetString(bytes);
            }
            catch
            {
                decode = code;
            }
            return decode;
        } 
    }
}